import json

import requests
if __name__ == '__main__':
    url= 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsList'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
    }
    id_list = []
    all_data_list = []
    for page in range(1,7):
        page = str(page)
        data= {
            'on':'true',
            'page': page,
            'pageSize':'15',
            'productName':'',
            'conditionType':'1',
            'applyname':'',
            'applysn':'',
        }
        json_id = requests.post(url=url, data=data, headers=headers).json()
        for dic in json_id['list']:
            id_list.append(dic['ID'])

    # 获取企业详情数据
    post_url = 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsById'
    for id in id_list:
        data = {
            'id': id
        }
        detail_json = requests.post(url=url, data=data, headers=headers).json()
        all_data_list.append(detail_json)

    fp = open('./alldata.json', 'w', encoding='utf-8')
    json.dump(all_data_list, fp=fp, ensure_ascii=False)
    print('over!!')